<%@ page language="java" import="java.util.*,java.sql.*"
	pageEncoding="UTF-8"%>

<html>
	<head>


	</head>

	<body>
	<center>
		<h1>登陆成功！<%=request.getParameter("user")%></h1>
		<br />
		<a href="login.jsp">返回重新登陆</a>
		<hr>
		<h1>
			用戶信息表
		</h1>
		<%
			//===============分页的功能==============
			int pageSize = 5;// 一页显示几条记录
			int pageNow = 1;// 希望显示第几页
			int rowCount = 0;// 共有几条记录（查表）
			int pageCount = 0;// 共有几页（计算出来）

			//接受用户希望显示的页数
			String s_pageNow = request.getParameter("pageNow");
			if (s_pageNow != null) {

				//接受到pageNow
				pageNow = Integer.parseInt(s_pageNow);
			}

			// 连接数据库
			Class.forName("com.mysql.jdbc.Driver");

			// 得到连接
			Connection ct = DriverManager.getConnection(
					"jdbc:mysql://127.0.0.1:3306/test1", "root", "root");

			// 创建Statement
			Statement sm = ct.createStatement();
			//查询
			ResultSet rs = sm.executeQuery("select count(*) from users");

			if (rs.next()) {

				rowCount = rs.getInt(1);
			}
			//计算pageCount
			if (rowCount % pageSize == 0) {
				pageCount = rowCount / pageSize;

			} else {

				pageCount = rowCount / pageSize + 1;
			}
			//查询出需要显示的记录
			rs = sm.executeQuery("select * from users LIMIT  " + pageSize
					* (pageNow - 1) + " , " + pageSize + " ");

			//显示
		%>
		<table border="1">
			<tr>
				<th>用户id</th><th>用户名字</th><th>密码</th><th>电邮</th><th>级别</th></tr>

			<%
				while (rs.next()) {
			%>
			<tr>
				<th><%=rs.getInt(1)%></th>
				<th><%=rs.getString(2)%></th>
				<th><%=rs.getString(3)%></th>
				<th><%=rs.getString(4)%></th>
				<th><%=rs.getString(5)%></th>
			</tr>
			<%
				}
			%>
		</table>
		<%
		
			//上一页
			if(pageNow!=1){
			out.println("<a href=wel.jsp?pageNow="+(pageNow-1)+">上一页</a>");
			}
			//显示超链接
			for (int i = 1; i <= pageCount; i++) {
				out.println("<a href=wel.jsp?pageNow=" + i + ">[" + i+ "]</a>");
			}
			//下一页
			if(pageNow!=pageCount){
			out.println("<a href=wel.jsp?pageNow="+(pageNow+1)+">下一页</a>");
			}
		%>
	<hr>
	</center>
	</body>
</html>
